// pages/hotel/index.js
const App = getApp()
const chooseLocation = requirePlugin('chooseLocation');
const api = require('../../utils/requst.js').API;
Page({

  /**
   * 页面的初始数据
   */
  // {address: "贵州省贵阳市清镇市百花路"
  //   city: "贵阳市"
  //   district: "清镇市"
  //   latitude: 26.566973
  //   longitude: 106.467461
  //   name: "清镇市碧翠红枫(百花路西200米)"
  //   province: "贵州省"}
  data: {
    top:0,
    num:0,
    date: '2020-09-01',
    enddate: '2020-09-10',
    array: [{id:"aa",name:"111"},{id:"aa",name:"222"},{id:"aa",name:"333"}],
    location:{name: ""},
    pageSize:10,
    pageNum: 1,
    list: [],
    loadState:1
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let top = 58+App.globalData.systemInfo.statusBarHeight + App.globalData.menuButton.height + (App.globalData.menuButton.top - App.globalData.systemInfo.statusBarHeight)*2
    console.log(top)
    this.setData({top:top})
    this.getData()
  },
  getData(){
    api.getPageHotelList({pageSize:this.data.pageSize,pageNum: this.data.pageNum,}).then(res=>{
      var list = res.data.data.records
      if(list.length<this.data.pageSize){
        this.setData({
          loadState:3
        })
      }else{
        this.setData({
          pageNum:this.data.pageNum+1,
          loadState:1
        })
      }
      this.setData({list:this.data.list.concat(list)})
  })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    const location = chooseLocation.getLocation();
    if(location){
      this.setData({location})
    }
  },
  change(e){
    console.log(e.detail)
  },
  bindDateChange: function(e) {
    this.setData({
      date: e.detail.value
    })
  },
  endChange: function(e) {
    this.setData({
      enddate: e.detail.value
    })
  },
  lenChange(e){
    console.log(e)
    let value = e.detail.value;
    this.setData({num:value.length})
  },
  tohotelDetail(e){
    let id = e.currentTarget.dataset['id'];
    wx.navigateTo({
      url: '../hotelDetail/index?id='+id,
    })
  },
  goGetLocation(){
    const key = 'N4PBZ-G2UWQ-X545S-GES3K-HS7J5-RXBNX'; //使用在腾讯位置服务申请的key
    const referer = '金刚统筹-用户端'; //调用插件的app的名称
    const category = '饭店,酒店酒楼';
    wx.navigateTo({
      url: `plugin://chooseLocation/index?key=${key}&referer=${referer}&category=${category}`
    });
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.loadState==1){
      this.getData()
    }
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})